package com.reebake.ideal.verify.code.core;

import cn.hutool.core.util.RandomUtil;
import com.reebake.ideal.verify.code.constants.VerifyCodeType;
import com.reebake.ideal.verify.code.properties.VerifyCodeProperties;
import lombok.RequiredArgsConstructor;

/**
 * 验证码生成器
 */
@RequiredArgsConstructor
public class VerifyCodeGenerator {

    private final VerifyCodeProperties verifyCodeProperties;

    public String generate() {
        String baseString = RandomUtil.BASE_CHAR_NUMBER;
        if (VerifyCodeType.NUMBER.equals(verifyCodeProperties.getCodeType())) {
            baseString = RandomUtil.BASE_NUMBER;
        } else if (VerifyCodeType.CHAR.equals(verifyCodeProperties.getCodeType())) {
            baseString = RandomUtil.BASE_CHAR;
        }
        return RandomUtil.randomString(baseString, verifyCodeProperties.getSize());
    }

}
